package com.hspedu.single_;

/**
 * 懒汉模式
 */
public class SingleTest02 {
    public static void main(String[] args) {
        System.out.println(B02.n1);
        B02 b01 = B02.getInstance();
        B02 b02 = B02.getInstance();
        System.out.println(b01);
        System.out.println(b02 == b01);
    }
}


class B02{
    public static int n1 = 100;
    private String name;
    private static B02 b02;

    public B02(String name) {
        System.out.println("构造器被调用~~");
        this.name = name;
    }

    public static B02 getInstance(){
        if(b02 == null){
            b02  = new B02("小龙");
        }
        return b02;
    }

    @Override
    public String toString() {
        return "B02{" +
                "name='" + name + '\'' +
                '}';
    }
}